import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LIUYANJIAO
 * Date: 2024-10-15
 * Time: 19:14
 */
class MinStack {

    Stack stack=new Stack<>();
    Stack Min=new Stack<>();

    public MinStack() {

    }

    public void push(int val) {
        stack.push(val);
        if(Min.empty()|| Min.peek().equals(val)){
            Min.push(val);
        }
    }

    public void pop() {
        if(stack.pop().equals(Min.peek())){
            Min.pop();
        }
    }

    public int top() {
        return (int) stack.peek();
    }

    public int getMin() {
        return (int)Min.peek();
    }
}
 class ListNode {
       int val;
       ListNode next;
    ListNode() {}
     ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 }

class Solution {
    public static ListNode removeElements(ListNode head, int val) {
        if(head==null) return null;
        ListNode pcur=head;
        while(pcur!=null&&pcur.val==val){
            pcur= pcur.next;
            head=head.next;
        }
        while(pcur!=null&&pcur.next!=null){
            if(pcur.next.val==val){
                pcur.next=pcur.next.next;
            }else{
                pcur=pcur.next;
            }

        }
        return head;
    }

    public static void main1(String[] args) {
        ListNode p=new ListNode(1);
        p.next=new ListNode(2);
        p.next.next=new ListNode(2);
        p.next.next.next=new ListNode(1);
        System.out.println(removeElements(p,2));

    }
}

class Solution1 {

    public  static List<List<Integer>> generate(int numRows) {
        List<List<Integer>> l=new ArrayList<>();
        for (int i = 0; i < numRows; i++) {
            l.add(new ArrayList<>());
            for(int j=0;j<=i;j++){
                if(j==0||j==i){
                    l.get(i).add(1);
                }
                if(j>0&&j<i){
                    int n=l.get(i-1).get(j-1)+l.get(i-1).get(j);
                    l.get(i).add(n);
                }
            }
        }return l;

    }

}
public class Main {

}